<!DOCTYPE html>
<html>
<head>
    <title>Physics Diagram: Magnetic Force on a Proton</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }
        canvas {
            border: 1px solid #ccc;
            background-color: #fff;
        }
    </style>
</head>
<body>
<canvas id="physicsCanvas" width="800" height="400"></canvas>
<script>
    const canvas = document.getElementById('physicsCanvas');
    const ctx = canvas.getContext('2d');

    // Set common styles
    ctx.strokeStyle = 'black';
    ctx.fillStyle = 'black';
    ctx.textAlign = 'left';
    ctx.textBaseline = 'middle';

    // --- Draw the Wire ---
    ctx.lineWidth = 4;
    const wireY1 = 280;
    const wireY2 = 320;
    const wireX1 = 20;
    const wireX2 = 780;

    ctx.beginPath();
    ctx.moveTo(wireX1, wireY1);
    ctx.lineTo(wireX2, wireY1);
    ctx.stroke();

    ctx.beginPath();
    ctx.moveTo(wireX1, wireY2);
    ctx.lineTo(wireX2, wireY2);
    ctx.stroke();

    // --- Draw Electron Flow Arrows ---
    ctx.lineWidth = 1.5;
    const arrowY = (wireY1 + wireY2) / 2; // Center of the wire: 300
    const arrowLength = 50;
    const arrowHeadSize = 10;
    
    function drawLeftArrow(x, y, len, headSize) {
        // x is the position of the arrowhead
        const startX = x + len;
        const endX = x;
        ctx.beginPath();
        ctx.moveTo(startX, y);
        ctx.lineTo(endX, y);
        // Arrowhead
        ctx.moveTo(endX, y);
        ctx.lineTo(endX + headSize, y - headSize * 0.6);
        ctx.moveTo(endX, y);
        ctx.lineTo(endX + headSize, y + headSize * 0.6);
        ctx.stroke();
    }

    // Place arrows inside the wire, from right to left
    drawLeftArrow(680, arrowY, arrowLength, arrowHeadSize);
    drawLeftArrow(590, arrowY, arrowLength, arrowHeadSize);
    drawLeftArrow(500, arrowY, arrowLength, arrowHeadSize);
    drawLeftArrow(410, arrowY, arrowLength, arrowHeadSize);
    drawLeftArrow(320, arrowY, arrowLength, arrowHeadSize);

    // --- Draw an Electron Particle and Label ---
    const electronX = 730;
    const electronY = arrowY;
    
    // Electron dot
    ctx.beginPath();
    ctx.arc(electronX, electronY, 6, 0, 2 * Math.PI);
    ctx.fill();

    // Electron label
    ctx.font = 'bold 30px serif';
    ctx.fillText('e⁻', electronX + 12, electronY + 3);
    
    // --- Draw the Proton ---
    const protonX = 400;
    const protonY = 180;

    // Proton dot
    ctx.beginPath();
    ctx.arc(protonX, protonY, 7, 0, 2 * Math.PI);
    ctx.fill();

    // Proton label
    ctx.font = 'bold 30px serif';
    ctx.fillText('proton', protonX + 15, protonY + 3);
    
    // --- Draw the Velocity Vector ---
    ctx.lineWidth = 2.5;
    const vectorLength = 80;
    const vectorHeadSize = 12;
    
    // The vector is detached from the proton dot, placed above it
    const vectorStartX = protonX;
    const vectorStartY = protonY - 20; 
    const vectorEndY = vectorStartY - vectorLength;

    // Vector line
    ctx.beginPath();
    ctx.moveTo(vectorStartX, vectorStartY);
    ctx.lineTo(vectorStartX, vectorEndY);
    ctx.stroke();
    
    // Arrowhead
    ctx.beginPath();
    ctx.moveTo(vectorStartX, vectorEndY);
    ctx.lineTo(vectorStartX - vectorHeadSize * 0.6, vectorEndY + vectorHeadSize);
    ctx.moveTo(vectorStartX, vectorEndY);
    ctx.lineTo(vectorStartX + vectorHeadSize * 0.6, vectorEndY + vectorHeadSize);
    ctx.stroke();
    
    // Velocity label 'v'
    ctx.font = 'italic bold 30px serif';
    ctx.fillText('v', vectorStartX + 10, vectorEndY + 5);

</script>
</body>
</html>